from sqlite3.dbapi2 import Timestamp
from turtle import mode
from django.db import models
import time

from torch import t
# Create your models here.


class BaseModel(models.Model):
    """
    基础类
    """
    id = models.AutoField(primary_key=True)
    time_stamp = models.BigIntegerField(default=time.time() * 1000,
                                        help_text='时间戳')

    def save(self, *args, **kwargs):
        self.time_stamp = time.time() * 1000
        super(BaseModel, self).save(*args, **kwargs)

    class Meta:
        abstract = True


class PcapBaseModel(BaseModel):
    """
    与pcap相关的基础类
    """
    owner_ip = models.CharField(max_length=128, help_text='此条记录属于此ip')
    destinate_ip = models.CharField(max_length=128, help_text='记录对应的ip')

    class Meta:
        abstract = True


class NodeInfo(BaseModel):
    """
    注册节点信息
    """
    host_ip = models.CharField(max_length=128, help_text="节点ip")
    public_key = models.CharField(max_length=256, help_text="公钥")
    private_key = models.CharField(max_length=256, help_text="私钥")

    class Meta:
        db_table = "node_info"


class NodeTrustCount(PcapBaseModel):
    """
    节点之间信任值信息
    """
    trust_total = models.FloatField(default=0, help_text='加权后获得的信任值')

    class Meta:
        db_table = "node_trust_count"


class NodeChallengeRecord(PcapBaseModel):
    """
    challenge信息存储
    """
    challenge = models.CharField(max_length=128,
                                 default="",
                                 help_text='签名后pcap地址')
    feedback = models.CharField(max_length=128,
                                default="",
                                help_text='对于签名后pcap的解析结果')
    score = models.FloatField(default=0, help_text='对于此次challenge的评分')

    class Meta:
        db_table = "node_challenge_record"